package com.hsoft.zhxy.app.xtgl_02_01.service.impl;


import com.hsoft.zhxy.app.xtgl_02_01.mapper.JcggXtcsMapper;
import com.hsoft.zhxy.app.common.model.entity.JcggXtcs;
import com.hsoft.zhxy.app.xtgl_02_01.service.JcggXtcsService;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.hsoft.zhxy.common.base.BaseService;
import com.hsoft.zhxy.common.result.ResultBody;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

 /**
 * All rights Reserved, Designed By 哈尔滨工业大学软件工程股份有限公司
 * 
 * @Title: 系统参数 Service层接口实现类
 * @Package 
 * @Description: 
 * @author: system
 * @date: 2020-10-26
 */
@Log4j2
@Service
public class JcggXtcsServiceImpl extends BaseService implements JcggXtcsService {

    @Autowired
    private JcggXtcsMapper jcggXtcsMapper;


     /**
     * 查询单条数据
     * @param jcggXtcs
     * @return
     */
    public JSONObject findOne(JcggXtcs jcggXtcs) {
        JcggXtcs rs = jcggXtcsMapper.selectOne(new QueryWrapper<JcggXtcs>().setEntity(jcggXtcs));
        return ResultBody.setData(rs);
    }


    /**
     * 查询列表数据
     * @param jcggXtcs
     * @return
     */
    public JSONObject findList(JcggXtcs jcggXtcs) {
        List<JcggXtcs> list = jcggXtcsMapper.selectList(new QueryWrapper<JcggXtcs>().setEntity(jcggXtcs));
        return ResultBody.setData(list);
    }


    /**
     * 查询分页数据
     * @param jcggXtcs
     * @param page
     * @param pageSize
     * @return
     */
    public JSONObject findListByPage(JcggXtcs jcggXtcs, long page, long pageSize) {

        Page<JcggXtcs> pageObj = new Page<JcggXtcs>(page, pageSize);
        IPage<JcggXtcs> result = jcggXtcsMapper.selectPage(pageObj, new QueryWrapper<JcggXtcs>().setEntity(jcggXtcs));

        return ResultBody.setData(result.getTotal(), result.getRecords());
    }


    /**
     * 新增
     * @param jcggXtcs
     * @return
     */
    public JSONObject add(JcggXtcs jcggXtcs) {
        jcggXtcs.setCjsj(LocalDateTime.now());
        jcggXtcs.setCjr(getYhid());
        jcggXtcs.setBgsj(LocalDateTime.now());
        jcggXtcs.setBgr(getYhid());
        return ResultBody.setData(jcggXtcsMapper.insert(jcggXtcs));
    }


    /**
     * 修改
     * @param jcggXtcs
     * @return
     */
    public JSONObject update(JcggXtcs jcggXtcs) {
        jcggXtcs.setBgsj(LocalDateTime.now());
        jcggXtcs.setBgr(getYhid());
        return ResultBody.setData(jcggXtcsMapper.updateById(jcggXtcs));
    }


    /**
     * 删除
     * @param jcggXtcs
     * @return
     */
    public JSONObject delete(JcggXtcs jcggXtcs) {
        return ResultBody.setData(jcggXtcsMapper.delete(new QueryWrapper<JcggXtcs>().setEntity(jcggXtcs)));
    }


}
